package com.crowd.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.crowd.dao.DaDao;
import com.crowd.entity.Da;

import utill.DButill;

public class DaDaoimpl extends DButill implements DaDao {

	@Override
	public List<Da> findAll() {
		String sql="select * from da";
		List<Da> das=new ArrayList<Da>();
		try {
			open_db();
			pst=conn.prepareStatement(sql);
			
			rs=pst.executeQuery();
			
			while (rs.next()) {
				Da da=new Da();
				da.setName(rs.getString("name"));
				da.setBonus(rs.getString("bonus"));
				da.setPurpose(rs.getString("purpose"));
				da.setForm(rs.getString("form"));
				da.setRule(rs.getString("rule"));
				das.add(da);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return das;
	}

	@Override
	public boolean add(Da da) {
		String sql="INSERT da VALUES(?,?,?,?,?)";
		int sult=0;
		try {
			open_db();
			pst=conn.prepareStatement(sql);
			pst.setString(1, da.getName());
			pst.setString(2, da.getBonus());
			pst.setString(3, da.getPurpose());
			pst.setString(4, da.getForm());
			pst.setString(5, da.getRule());
			sult=pst.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return sult>0;
	}

	@Override
	public List<Da> danAll(Da da) {
		String sql="select * from da where name ='?'";
		List<Da> daa=new ArrayList<Da>();
		try {
			open_db();
			pst=conn.prepareStatement(sql);
			pst.setString(1,da.getName());
			rs=pst.executeQuery();
			while (rs.next()) {
				Da da1=new Da();
				da1.setName(rs.getString("name"));
				da1.setBonus(rs.getString("bonus"));
				da1.setPurpose(rs.getString("purpose"));
				da1.setForm(rs.getString("form"));
				da1.setRule(rs.getString("rule"));
				daa.add(da1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return daa;
	}

}
